<template>
  <v-dialog :value="visibleDialog" max-width="300px" persistent>
    <v-card>
      <v-card-title>{{ title }}</v-card-title>
      <v-card-text>{{ content }}</v-card-text>
      <v-card-actions>
        <v-spacer></v-spacer>
        <v-btn color="success" depressed dark @click="confirm">
          {{ yesText }}
        </v-btn>
        <v-btn color="error" depressed dark @click="cancel">
          {{ noText }}
        </v-btn>
      </v-card-actions>
    </v-card>
  </v-dialog>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { BtnCallback, ConfirmDialog } from "../../types";

@Component
export default class Confirm extends Vue implements ConfirmDialog {
  title = "提示";
  content = "";
  yesText = "确认";
  noText = "取消";
  visibleDialog = true;
  OnConfirm: BtnCallback | null = null;
  OnCancel: BtnCallback | null = null;

  confirm(): void {
    if (typeof this.OnConfirm === "function") {
      this.OnConfirm();
    }
  }
  cancel(): void {
    if (typeof this.OnCancel === "function") {
      this.OnCancel();
    }
  }
  Show(): void {
    this.visibleDialog = true;
  }
  Hide(): void {
    this.visibleDialog = false;
  }
  RemoveElement(): void {
    this.$destroy();
    this.$el?.parentNode?.removeChild(this.$el);
  }
}
</script>
